﻿<%@ Page Title="企业微信信息管理" Language="C#" MasterPageFile="~/master/m.master" %>

<script runat="server">

</script>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <link href="../assets/css/plugins/jsTree/style.min.css" rel="stylesheet" />
    <link href="../assets/css/plugins/iCheck/customsmall.css" rel="stylesheet" />
    <link href="../assets/css/plugins/bootstrap-select/bootstrap-select.min.css" rel="stylesheet" />
    <style>
        .system-box .right-side{width: 100%;}
        .system-box .right-content-box{overflow: hidden;}
        .mainContent { height: 100%;background-color: #ffffff; min-width: 650px; }
        .mainContent .part{height: 100%; display: inline-block; background-color: #ffffff; vertical-align: top; border: 1px solid #dddddd;}
        .mainContent .part .title{border-bottom: 1px solid #dddddd; height: 30px; line-height: 30px; padding-left: 5px;    background-color: #eee;}
        .leftPart { width: calc(100% - 410px);  min-width: 320px;overflow: auto;}
        .MessagePart{ width: 405px;overflow: auto;}
        .rightPart .titleText { height: 30px; line-height: 30px; display: inline-block;  }
        .searchbox{width: 180px; display: inline-block; float: right;}
        .btn-filter-users { -ms-border-radius: 0px; border-radius: 0px; }

        table { table-layout: fixed; }
        td { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
        .dropdownColor { color: #000000 !important; background-color: #ffffff !important; border-color: #ccc !important; }
        .form-horizontal { margin-top: 10px; }
        #MessageList tr.check, .table-select tbody tr.check td:first-child { border-left: 4px solid #7acf89; }
        #MessageList tr.check td, .table-select tbody tr.check td { background: #dff0d8; color: #222121; }
        .leftPart .form-horizontal .form-group { margin-right: 0px; }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="main" runat="Server">
    <div class="system-box">
        <div class="right-side">
            <div class="btns-container"></div>
            <div class="right-content-box">
                <%--<div class="header-tips">企业微信用户报表授权</div>--%>
                <div class="mainContent">
                    <div class="MessagePart part">
                        <div class="title">
                            <div  class="titleText">
                                企业微信信息列表
                            </div>
                        </div>
                        <div id="">
                            <table class="footable table table-stripped table-list">
                                <thead>
                                <tr>
                                    <th style="width: 35px;"> </th>
                                    <th>企业名称</th>
                                    <th style="width: 160px;">CorpID</th>
                                </tr>
                                </thead>
                                <tbody id="MessageList"></tbody>
                            </table>
                        </div>
                    </div>
                    <div class="leftPart part">
                        <div class="title">
                            消息模板内容
                        </div>
                        <div>
                          <form class="form-horizontal">
                             
                                <div class="form-group">
                                    <label class="col-sm-2 control-label" for="CorpID">CorpID</label>
                                    <div class="col-sm-9">
                                        <input class="form-control" type="text" id="CorpID" placeholder="">
                                    </div>
                                </div>
                              
                              <div class="form-group">
                                  <label class="col-sm-2 control-label" for="CorpName">CorpName</label>
                                  <div class="col-sm-9">
                                      <input class="form-control" type="text" id="CorpName" placeholder="">
                                  </div>
                              </div>

                                <div class="form-group">
                                    <label class="col-sm-2 control-label" for="CorpSercet">CorpSercet</label>
                                    <div class="col-sm-9">
                                        <input class="form-control" type="text" id="CorpSercet" placeholder="">
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="col-sm-2 control-label" for="AgentId">AgentId</label>
                                    <div class="col-sm-9">
                                        <input class="form-control" type="text" id="AgentId" placeholder="">
                                    </div>
                                </div>
                                
                                <div class="form-group">
                                    <label class="col-sm-2 control-label" for="AgentName">AgentName</label>
                                    <div class="col-sm-9">
                                        <input class="form-control" type="text" id="AgentName" placeholder="">
                                    </div>
                                </div>
                                
                                <div class="form-group">
                                    <label class="col-sm-2 control-label" for="CommunicationSercet">CommunicationSercet</label>
                                    <div class="col-sm-9">
                                        <input class="form-control" type="text" id="CommunicationSercet" placeholder="">
                                    </div>
                                </div>
                             

                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="footer" runat="Server">
    <script src="../assets/js/plugins/iCheck/icheck.min.js"></script>
    <script src="../assets/js/plugins/iCheck/icheckAll.js"></script>
    <script src="../assets/js/page/rScroll.js"></script>
    <script src="../assets/js/page/pageControl.js"></script>
    <%--<script src="../assets/js/page/tableControl.js"></script>--%>


    <script type="text/html" id="tpl-msg-item">
        {{# for(var i = 0, len = d.length; i < len; i++){ }}
        <tr {{# if(i%2 == 0){ }} class="gradeX footable-even"
            {{# }else{ }} class="gradeX footable-odd" {{# } }}>
            <td class="CID" style="display: none;">{{d[i].CID}}</td>
            <td><input type="radio"  name="msg"  class="checkPlan" data-index="{{i}}" /></td>
            <td class="CorpName">{{d[i].CorpName}}</td>
            <td class="CorpID">{{d[i].CorpID}}</td>
        </tr>
        {{# } }}
    </script>
    <script>

        $(document).ready(function () {
            //layer.msg('玩命加载中……', { icon: 16, shade: 0.01, time: 0, maxWidth: 200 });

            //模块ID
            var ModuleID = Y.getUrlParam("ModuleID");

            //获取按钮
            commonUtil.loadBtnList(ModuleID, function () {
                rScroll();
            });

            //自动高 DOCUMENT高减按钮栏+其它
            //$(".chooseArea .leftArea1").height($(document).height() - (35 + 145));

            var errorIfNull = function(val, msg) {
                var tmp = val || "";
                if (tmp === "") {
                    swal(msg, '', 'error');
                    return true;
                }
                return false;
            }

            var resetAllInput = function () {
                $('#CorpID').val("");
                $('#CorpSercet').val("");
                $('#CommunicationSercet').val("");
                $('#AgentId').val("");
                $('#AgentName').val("");
                $('#CorpName').val("");
            };

            var msgTemplateTypeChanged = function () {
                var msgType = $('#msgTemplateType').selectpicker('val');
                console.log(msgType);
                if (msgType === "NewsMsg") {
                    $('.templatePicUrl').show();
                } else {
                    $('.templatePicUrl').hide();
                }
            }

            //获取列表
            var loadMessageList = function () {
                pageControl.init('WxCorpInfo', 'GetWxCorpInfoList', {
                    needLayer: true,
                    alwaysCallBack: function () {
                        $('#MessageList').empty();
                    }
                }, function (result) {
                    var tBody = [];
                    if (!Y.checkNull(result)) {
                        if (result.data.length == 0) {
                            Y.NoData(body, 5);
                            return false;
                        }
                        var pl = document.getElementById('tpl-msg-item').innerHTML;
                        laytpl(pl).render(result.data, function (html) {
                            document.getElementById('MessageList').innerHTML = html;

                            $(".checkPlan").iCheck({
                                checkboxClass: "icheckbox_square-green",
                                radioClass: "iradio_square-green"
                            });

                            $('.checkPlan').on('ifChecked', function (event) {
                                $('.footable tr').removeClass('check');
                                $(this).parents('tr').addClass('check');
                            });

                            resetAllInput();
                        });
                        rScroll();
                    }
                });
            }


            //选中记录
            $('#MessageList').on('click', 'tr', function () {
                if ($(this).hasClass('check')) {
                    $('#MessageList tr').removeClass('check');
                    $('#MessageList tr .checkPlan').iCheck('uncheck');
                } else {
                    $('#MessageList tr').removeClass('check');
                    $(this).addClass('check');

                    $('#MessageList tr .checkPlan').iCheck('uncheck');
                    $(this).find('.checkPlan').iCheck('check'); 


                    //getdetail
                    var id = $(this).find('.CID').text();
                    Y.API2('WxCorpInfo', 'GetWxCorpInfo', { CID: id }, function (data) {
                        console.log(data)
                        if (data.Success == false) {
                            swal(data.Message, '', 'error');
                        } else {
                            $('.leftPart #CorpID').val(data.CorpID);
                            $('.leftPart #CorpSercet').val(data.CorpSercet);
                            $('.leftPart #CommunicationSercet').val(data.CommunicationSercet);
                            $('.leftPart #AgentId').val(data.AgentId);
                            $('.leftPart #AgentName').val(data.AgentName);
                            $('.leftPart #CorpName').val(data.CorpName);
                        }
                    });
                }

                //
            });

            //提交
            $(document).on("click", "#btn-save", function () {

                var tr = $('#MessageList .checkPlan:checked').parents('tr');
                var cid = $(tr).find('.CID').text() || 0;

                var action = cid === 0 ? "AddWxCorpInfo" : "UpdateWxCorpInfo";
                var msg = cid === 0 ? "添加成功" : "修改成功";

                var obj = {};
                obj.CID = cid;
                obj.CorpID = $('#CorpID').val();
                obj.CorpSercet = $('#CorpSercet').val();
                obj.CommunicationSercet = $('#CommunicationSercet').val();
                obj.AgentId = $('#AgentId').val();
                obj.AgentName = $('#AgentName').val();
                obj.CorpName = $('#CorpName').val();

                if (errorIfNull(obj.CorpID, "CorpID不能为空") ||
                    errorIfNull(obj.CorpSercet, "CorpSercet不能为空") ||
                    errorIfNull(obj.CommunicationSercet, "CommunicationSercet不能为空") ||
                    errorIfNull(obj.AgentId, "AgentId不能为空") ||
                    errorIfNull(obj.AgentName, "AgentName不能为空") ||
                    errorIfNull(obj.CorpName, "CorpName不能为空")) {
                    return false;
                }

                Y.API2('WxCorpInfo', action, obj, function (data) {
                    if (data.Success == false) {
                        swal(data.Message, '', 'error');
                    } else {
                        swal(msg, '', 'success');
                        resetAllInput();
                        loadMessageList();
                    }
                });
            });

            $(document).on("click", "#addBtn", function() {
                resetAllInput();

                $('#MessageList tr').removeClass('check');
                $('#MessageList tr .checkPlan').iCheck('uncheck');
            });

            $(document).on("click", "#btn-search", function () {
                loadMessageList();
            });

            $(document).on("click", "#deleteBtn", function () {
                var tr = $('#MessageList .checkPlan:checked').parents('tr');
                var cid = $(tr).find('.CID').text() || 0;

                if (cid === 0) {
                    swal("请选择要删除的消息模板", '', 'error');
                    return false;
                }

                swal({
                    title: "您确定要删除这条记录吗",
                    text: "删除后将无法恢复，请谨慎操作！",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "删除",
                    cancelButtonText: "取消",
                    closeOnConfirm: false
                }, function () {
                    Y.API2('WxCorpInfo', "RemoveWxCorpInfo", { CID: cid }, function (data) {
                        if (data.Success == false) {
                            swal(data.Message, '', 'error');
                        } else {
                            swal("删除成功", '', 'success');
                            resetAllInput();
                            loadMessageList();
                        }
                    });
                });
            });

            $('#msgTemplateType').on('changed.bs.select', function (e) {
                msgTemplateTypeChanged();
            });

            //默认加载消息模板
            loadMessageList();
        })
    </script>
</asp:Content>

